/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "collectible.h"
#include "gameengine.h"

/*! \class Collectible
  Base class for collectible game object. Collectible wraps.
*/

/*!
  Constructor for collectible.

  \a type Type of the game object as ::GameObjectType

  \a frame Current frame number. When the GameObject was created.

  \a gameObjectRadius Radius of the game object as ::FPtype.

  \a gameObjectSpeedLimit Maximum speed of the game object as ::SpeedLimit.

  \a rewindEnabled Is the rewind mode enabled.

  \a mass Mass of the game object as ::GameObjectMass.

  \a scoreValue Score value of the game object as ::ScoreValue.

  \a lifeCycleFrames Life cycle of the collectible as frames.
*/
Collectible::Collectible(GameObjectType type, int frame, FPtype gameObjectRadius, 
                         SpeedLimit gameObjectSpeedLimit, bool rewindEnabled, GameObjectMass mass, 
                         ScoreValue scoreValue, int lifeCycleFrames) 
    : WrappingGameObject(type, frame, gameObjectRadius, gameObjectSpeedLimit, rewindEnabled, mass, 
                       scoreValue)
    , lifeCycleInFrames(lifeCycleFrames)
{
}

/// How many frames will collectible have its lifecycle left.
bool Collectible::lifeCycleLeft(int frames) const
{
    if ((frames - storedBornFrame) < lifeCycleInFrames)
        return true;
    else 
        return false;
}

/*! \class HyperJump
  Collectible game object for hyper jump.
*/

/*!
  Constructor for hyper jump.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.

  \a radius Radius of the game object as ::FPtype.
*/
HyperJump::HyperJump(int frame, bool rewindEnabled, FPtype radius) 
    : Collectible(TypeCollectibleHyperJump, frame, radius, SpeedLimitMedium,
                rewindEnabled, MassTiny, ScoreHyperJump, LifeCycleHyperJump)
{
}

/*! \class Bomb
  Collectible game object for bomb.
*/

/*!
  Constructor for bomb.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.

  \a radius Radius of the game object as ::FPtype.
*/
Bomb::Bomb(int frame, bool rewindEnabled, FPtype radius) 
    : Collectible(TypeCollectibleBomb, frame, radius, SpeedLimitMedium, rewindEnabled,
                  MassLarge, ScoreBomb, LifeCycleBomb)
{
}

/*! \class RotatingCollectible
  Rotating collectible game object.
*/

/*!
  Constructor for rotating collectible.

  \a type Type of the game object as ::GameObjectType

  \a frame Current frame number. When the GameObject was created.

  \a gameObjectRadius Radius of the game object as::FPtype.

  \a gameObjectSpeedLimit Maximum speed of the game object as ::SpeedLimit.

  \a rewindEnabled Is the rewind mode enabled.

  \a mass Mass of the game object as ::GameObjectMass.

  \a scoreValue Score value of the game object as ::ScoreValue.

  \a lifeCycleFrames Life cycle of the collectible as frames.
*/
RotatingCollectible::RotatingCollectible(GameObjectType type, int frame, FPtype gameObjectRadius, 
                                         SpeedLimit gameObjectSpeedLimit, bool rewindEnabled, 
                                         GameObjectMass mass, ScoreValue scoreValue, 
                                         int lifeCycleFrames) 
    : Collectible(type, frame, gameObjectRadius, gameObjectSpeedLimit, rewindEnabled, mass, 
                  scoreValue, lifeCycleFrames)
{
}

/*! \class Mineral
  Base class for mineral collectibles. Mineral game object rotates.
*/

/*!
    Constructor for collectible mineral.

  \a type Type of the game object as ::GameObjectType

  \a frame Current frame number. When the GameObject was created.

  \a gameObjectSpeedLimit Maximum speed of the game object as ::SpeedLimit.

  \a rewindEnabled Is the rewind mode enabled.

  \a scoreValue Score value of the game object as ::ScoreValue.

  \a lifeCycleFrames Life cycle of the collectible as frames.
*/
Mineral::Mineral(GameObjectType type, int frame, SpeedLimit gameObjectSpeedLimit, 
                 bool rewindEnabled, ScoreValue scoreValue, int lifeCycleFrames)
    : RotatingCollectible(type, frame, GameEngine::GameObjectRadiusMineral, gameObjectSpeedLimit, 
                        rewindEnabled, MassTiny, scoreValue, lifeCycleFrames)
{
    GLfloat tmp_axis[3];
    tmp_axis[0] = GameEngine::getRandomF() - 0.50;
    tmp_axis[1] = GameEngine::getRandomF() - 0.50;
    tmp_axis[2] = GameEngine::getRandomF() - 0.50;
    GameEngine::normalizeVect3D_GLfloat(tmp_axis);

    setRotationAxis(0, tmp_axis[0]);
    setRotationAxis(1, tmp_axis[1]);
    setRotationAxis(2, tmp_axis[2]);

    GLfloat rotationSpeed = 0.1 + GameEngine::getRandomF() * 0.5;
    if (GameEngine::getRandomF() < 0.50) rotationSpeed = -rotationSpeed;
    setRotationSpeed(rotationSpeed);
}

/*! \class MineralA
  Type A mineral collectible.
*/

/*!
  Constructor for A type mineral.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.
*/
MineralA::MineralA(int frame, bool rewindEnabled) 
    : Mineral(TypeCollectibleMineralA, frame, SpeedLimitLow, rewindEnabled, ScoreMineralA, 
            LifeCycleMineralA)
{
}

/*! \class MineralB
  Type B mineral collectible.
*/

/*!
  Constructor for B type mineral.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.
*/
MineralB::MineralB(int frame, bool rewindEnabled) 
    : Mineral(TypeCollectibleMineralB, frame, SpeedLimitMedium, rewindEnabled, ScoreMineralB, 
            LifeCycleMineralB)
{
}

/*! \class MineralC
  Type C mineral collectible.
*/

/*!
  Constructor for C type mineral.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.
*/
MineralC::MineralC(int frame, bool rewindEnabled) 
    : Mineral(TypeCollectibleMineralC, frame, SpeedLimitHigh, rewindEnabled, ScoreMineralC, 
            LifeCycleMineralC) 
{
}

/*! \class MineralD
  Type D mineral collectible.
*/

/*!
  Constructor for D type mineral.

  \a frame Current frame number. When the GameObject was created.

  \a rewindEnabled Is the rewind mode enabled.
*/
MineralD::MineralD(int frame, bool rewindEnabled) 
    : Mineral(TypeCollectibleMineralD, frame, SpeedLimitExtraHigh, rewindEnabled, ScoreMineralD, 
            LifeCycleMineralD)
{
}
